package com.linkmed.storage.utils;

import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import com.obs.services.model.ListBucketsRequest;
import com.obs.services.model.ObsBucket;

import java.util.List;

public class ObsClientFactory {

    private static ObsClient obsClient;

    private static final String endPoint ="http://140.249.19.145/storage"; //"http://169.255.194.184";//"http://11.125.1.249";//"//
    private static final String ak = "6WNRCBYLMT5OLYHOYWNC";
    private static final String sk = "QhSbEwDgGG1liQlEyCM5emC4AqflgzndutSbKMnD";



    public static ObsClient getObsClient(){
        try {
           /* ObsConfiguration os = new ObsConfiguration();
            os.setHttpProxy("140.249.19.145",80,"Administrator","Beijinglinkmed2021!@#^");
            os.setEndPoint(endPoint);*/
            if(null == obsClient){
               // obsClient = new ObsClient(ak,sk,os);
                obsClient = new ObsClient(ak, sk,endPoint);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obsClient;
    }

    public static void main(String[] args) {
        ObsClient obsClient = getObsClient();
        System.out.println(obsClient);
        ListBucketsRequest request = new ListBucketsRequest();
        request.setQueryLocation(true);
        List<ObsBucket> buckets = obsClient.listBuckets(request);
        for(ObsBucket bucket : buckets)
        {
            System.out.println("BucketName:" + bucket.getBucketName());
            System.out.println("CreationDate:" + bucket.getCreationDate());
            System.out.println("Location:" + bucket.getLocation());
        }
// 关闭obsClient
    }
}
